home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / wxreg.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  127 lines

  1. ; $Id: wxreg.pro,v 1.4 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; This code sample creates a widget application that checks
  7. ; to make sure that only one copy of itself is running.
  8.  
  9.  
  10.  
  11.  
  12.  
  13. PRO wxreg_event, event
  14. ; This is the event handler for the "Multiple Copies" widget.
  15.  
  16. ; Allow the event handler to set the value of the label:
  17. COMMON wxreg, label1, button2
  18.  
  19. ; Use WIDGET_CONTROL to get the user value of any widget touched and put
  20. ; that value into 'eventval':
  21.  
  22. WIDGET_CONTROL, event.id, GET_UVALUE = eventval
  23.  
  24. ; Perform actions based on the user value of the button that was pressed:
  25.  
  26. CASE eventval OF
  27.    'ANOTHER':BEGIN
  28.         ; Attempt to start invoke another copy of this example
  29.         wxreg, GROUP=event.top
  30.              END
  31.  
  32.    'DONE': BEGIN
  33.                 WIDGET_CONTROL, event.top, /DESTROY
  34.            END
  35.  
  36. ENDCASE
  37. END
  38.  
  39.  
  40.  
  41. PRO wxreg, GROUP=GROUP
  42. ; This is the procedure that creates a widget application that checks
  43. ; to make sure that only one copy of itself is running.  Widgets that
  44. ; use COMMON blocks could become corrupted if there were 
  45. ; several copies running at the same time.  The check for multiple
  46. ; copies is usually expressed as follows:
  47.  
  48. ;     IF (XREGISTERED("procedure_name") NE 0 THEN RETURN
  49.  
  50. ; This line is already in the widget template "XMNG_TMPL.PRO".
  51.  
  52.  
  53. ; Allow the event handler to set the value of the label:
  54. COMMON wxreg, label1, button2
  55.  
  56. ; Check to make sure that only one example may run at a time.
  57. ; Removing the following IF block will allow more than one
  58. ; invocation of the "wxreg" example to run concurrently:
  59.  
  60. IF(XREGISTERED("wxreg") GT 0) THEN BEGIN
  61.     WIDGET_CONTROL, label1, $
  62.         SET_VALUE='ONLY ONE INVOCATION OF "wxreg" IS ALLOWED'
  63.     ; Return here rather than actually starting another
  64.     WIDGET_CONTROL, button2, SENSITIVE=0
  65.     RETURN
  66. ENDIF
  67.  
  68. ; A top-level base widget with the title "X Registered Example" will
  69. ; hold the exclusive buttons:
  70.  
  71. base = WIDGET_BASE(TITLE = 'X Registered Example', $
  72.     /COLUMN)
  73.  
  74. ; Make the DONE button:
  75.  
  76. button1 = WIDGET_BUTTON(base, $
  77.                 UVALUE = 'DONE', $
  78.                 VALUE = 'DONE')
  79.  
  80. text1 = WIDGET_TEXT(base, $
  81.         /FRAME, $
  82.         VALUE = [ $
  83.             'This example will show how the XREGISTERED routine', $
  84.             'can be used to allow only one invocation of a', $
  85.             'given procedure.  The button below can be used to', $
  86.             'attempt to start another invocation of this example',$
  87.             'widget.', $
  88.             '', $
  89.             'The main procedure uses XREGISTERED to determine', $
  90.             'if the example is already running.  If it is, it', $
  91.             'does not allow another to start.', $
  92.             '', $
  93.             'The example also starts the XMANAGERTOOL.  This', $
  94.             'shows that the procedure "wxreg" is registered.', $
  95.             '', $
  96.             'Try modifying the main procedure so that it does', $
  97.             'not check to see if the example is already running.',$
  98.             'This should allow multiple invocations of the', $
  99.             'example to co-exist.  These multiple invocations', $
  100.             "should show up in the XMANAGERTOOL's list of", $
  101.             'registered widgets.' $
  102.             ], $
  103.         XSIZE=60, $
  104.         YSIZE=20)
  105.  
  106. ; The ANOTHER button:
  107. button2 = WIDGET_BUTTON(base, $
  108.                 UVALUE = 'ANOTHER', $
  109.                 VALUE = 'Attempt to Invoke Another "X Registered Example"')
  110.  
  111. ; A blank label is created. It holds the 'Only one copy...' message
  112. ; when an attempt to run another copy is made:
  113. label1 = WIDGET_LABEL(base, $
  114.         /FRAME, /DYNAMIC_RESIZE, $
  115.         VALUE = ' ')
  116.  
  117. ; Realize the widgets:
  118. WIDGET_CONTROL, base, /REALIZE
  119.  
  120. ; Use the xmanager to only register the widgets:
  121. XMANAGER, "wxreg", base, GROUP_LEADER=GROUP, /JUST_REG, /NO_BLOCK
  122.  
  123. ; Run the XMANAGER tool:
  124. XMTool, GROUP = base
  125.  
  126. END
  127.